package com.culture.bootdemo.model.vo;

import lombok.AllArgsConstructor;
import lombok.Data;

import java.math.BigDecimal;

/**
 * @Author: wenjl
 * @Date: 2021/3/15 16:30
 * @Description:
 */
@Data
@AllArgsConstructor
public class CSVDemoData {
    private long id;
    private String name;
    private Integer userId;

    public static String getPercent(Integer x, Integer y) {
        if (null == x || null == y || x.equals(0) || y.equals(0)) {
            return "0%";
        }
        return (new BigDecimal(String.valueOf(x)).divide(new BigDecimal(String.valueOf(y)), 2, BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal("100")).toPlainString()) + "%";

    }

    public static void main(String[] args) {
        Integer x = 500000;
        Integer y = 10000;
        System.out.println(getPercent22(x, y));
    }

    public static String getPercent22(Integer x, Integer y) {
        if (null == x || null == y || x.equals(0) || y.equals(0)) {
            return "0%";
        }
        BigDecimal divide = new BigDecimal(String.valueOf(x)).divide(new BigDecimal(String.valueOf(y)), 4, BigDecimal.ROUND_HALF_UP);
        BigDecimal multiply = divide.multiply(new BigDecimal("100"));
        return multiply.setScale(2, BigDecimal.ROUND_HALF_UP).toPlainString() + "%";
    }
}
